﻿using BouncingBallGame.Models;
using System;
using System.Linq;
using System.Windows.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace BouncingBallGame.Helpers
{
    public class PageManager
    {
        #region Fields

        private ICommand goToHomePageCommand;
        private ICommand goToPlayGamePageCommand;
        private ICommand goToEditLevelPageCommand;

        #endregion


        #region Properties

        public ICommand StartGame
        {
            get
            {
                if (this.goToPlayGamePageCommand == null)
                {
                    this.goToPlayGamePageCommand = new RelayCommand(PageManager.HandleGoToPlayGameCommand);
                }

                return this.goToPlayGamePageCommand;
            }
        }

        public ICommand EditLevel
        {
            get
            {
                if (this.goToEditLevelPageCommand == null)
                {
                    this.goToEditLevelPageCommand = new RelayCommand(PageManager.HandleGoToEditPageCommand);
                }

                return this.goToEditLevelPageCommand;
            }
        }

        public ICommand Home
        {
            get
            {
                if (this.goToHomePageCommand == null)
                {
                    this.goToHomePageCommand = new RelayCommand(PageManager.HandleGoToHomePageCommand);
                }

                return this.goToHomePageCommand;
            }
        }

        #endregion


        #region Constructor



        #endregion


        #region Methods        

        public static void HandleGoToPlayGameCommand(object parameter = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;
            GameLevelModel level = parameter as GameLevelModel;
            if (rootFrame != null && level != null)
            {
                rootFrame.Navigate(typeof(Pages.PlayGamePage), level);
            }
        }

        public static void HandleGoToEditPageCommand(object parameter = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;
            GameLevelModel level = parameter as GameLevelModel;
            if (rootFrame != null)
            {
                rootFrame.Navigate(typeof(Pages.EditLevelPage), level);
            }
        }

        public static void HandleGoToHomePageCommand(object parameter = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame != null)
            {
                rootFrame.Navigate(typeof(Pages.HomePage), null);
            }
        }

        #endregion
    }
}
